<template>
	<view>
		<view class="record-item" @click="goTicketDetail(item.id)" v-for="item in ticketList" :key="item.id">
			<view class="item-title">
				<view class="left-border"></view>
				<view class="left">{{ticketTypes[item['工单类型']]}}</view>
				<view class="center" v-if="item['工单状态'] == 'pending' || item['工单状态'] == 'unclaimed'" @click.stop="handleCancel">
					<view class="center-img">
						<image src="../../../static/icon/quxiao.png" mode=""></image>
					</view>
					<view v-if="item['工单状态'] == 'unclaimed' || item['工单状态'] == 'pending'" @click="cancel(item.id)">取消报事</view>
				</view>
				<view v-if="item['工单状态'] == 'unclaimed' || item['工单状态'] == 'pending'" class="right">待处理</view>
				<view class="handle" v-if="item['工单状态'] == 'handling'">处理中</view>
				<view class="complete" v-if="item['工单状态'] == 'completed'">已完成</view>
			</view>
			<view class="item-content">
				<view class="content-top un-evaluate">
					<view>报事编号 ：{{item['工单编号']}}</view>
					<view class="have-evaluate" v-if="item['工单状态'] === 'completed' && item['评价状态'] === 'rated'">已评价</view>
					<view v-else-if="item['工单状态'] === 'completed'" class="evaluate-icon">待评价</view>					
				</view>
				<view class="content-center">报事时间 ：{{item['创建时间']}}</view>
				<view v-if="item['报事描述'].trim() !== ''" class="content-bottom">报事描述 ：{{item['报事描述']}}</view>
				<view v-else class="content-bottom">报事描述 ：{{'无'}}</view>
			</view>
		</view>
	</view>
</template>

<script>
	export default {
		props: {
			ticketList: {
				type: Array,
				default: () => []
			}
		},
		data() {
			return {
				ticketTypes: this.$types.ticketType,
				params1: {
					id: null,
					操作类型: 'abandon'
				}
			}
		},
		methods: {
			goTicketDetail(id){
				uni.navigateTo({
					url: '../ticketDetail/ticketDetail?id=' + id
				})
			},
			handleCancel() {
				console.log('阻止冒泡')
			},
			setTabIndex(val) {
				this.tabCurrentIndex = val
			},
			cancel(id) {
				uni.showModal({
					title: '提示',
					content: '确认取消报事吗？',
					success: (res) => {
						if (res.confirm) {
							this.cancelTicket(id)
						} else if (res.cancel) {
							console.log('用户点击取消');
						}
					}
				})
			},
			cancelTicket(id) {
				this.params1.id = id
				this.$http2.post('ticketSystem/ticket/changeStatus',this.params1).then(res => {
					console.log(res)
					if(res.code === 10000){
						this.$emit('refresh')
						uni.showToast({
							title: '取消成功'
						})
					}
				})
			}
		}
	}
</script>

<style>
</style>
